Skip to content

feature/issue-19/implement-drawing-error-features#20

Merged
alperkent merged 3 commits into
mainfrom
alperkent/issue19
Apr 23, 2025
Merged

feature/issue-19/implement-drawing-error-features#20
alperkent merged 3 commits into
mainfrom
alperkent/issue19

Conversation

@alperkent
Copy link
Copy Markdown
Collaborator

Resolves #19.

@alperkent alperkent added enhancement New feature or request task A development task intended for Github Projects labels Apr 22, 2025
@alperkent alperkent self-assigned this Apr 22, 2025
@alperkent alperkent requested a review from Asanto32 April 22, 2025 14:42
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.69%. Comparing base (9570fda) to head (0723f64).
Report is 6 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main      #20      +/-   ##
===========================================
- Coverage   100.00%   97.69%   -2.31%     
===========================================
  Files            4        6       +2     
  Lines          115      130      +15     
===========================================
+ Hits           115      127      +12     
- Misses           0        3       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alperkent
Copy link
Copy Markdown
Collaborator Author

@Asanto32 I decided to exclude MSE and RMSE calculations for now, I'll explain why on our Wednesday meeting and if we decide to add them nonetheless I'll just commit it here before merging this PR.

Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments, the main question is why use shapely do begin with and not just scipy integration like you do in the test?

"""Feature extraction module for drawing error-based metrics in spiral drawing data."""

import numpy as np
from shapely import geometry, ops
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check their license and how it impacts using their package with our license. Not sure what BSD-3-Clause license is

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BSD-3-Clause looks pretty permissive, so I don't think there would be any issues:

BSD 3-Clause License

Copyright (c) 2007, Sean C. Gillies. 2019, Casper van der Wel. 2007-2022, Shapely Contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Comment thread tests/unit/test_drawing_error.py Outdated
lambda x: np.abs(np.sin(x) - np.sin(x + np.pi)), -np.pi / 2, 6 * np.pi / 4
)

class MockSpiral:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't have a dedicated class within a unit test

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually couldn't find a better way of doing this test so I left it like this hoping you might suggest a better way lol

Comment thread tests/unit/test_drawing_error.py Outdated
y1 = np.sin(x)
y2 = np.sin(x + np.pi)

expected_area, _ = integrate.quad(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This begs the question: If we can use integration to find the area under the curve here why do we need the shapely method?

Copy link
Copy Markdown
Collaborator Author

@alperkent alperkent Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use integration for this test which uses only sine waves, but the spiral data is a lot trickier. My initial goal was to convert Cartesian coordinates to polar and just use np.trapz but there are some issues with conversion to polar in the beginning segment of the data and resampling the reference spiral at the same angles with the drawn spiral, so I've decided not to do this. I will explain more during our meeting tomorrow.

Comment thread tests/unit/test_drawing_error.py Outdated
self.data = data
self.metadata = metadata

monkeypatch.setattr(models, "Spiral", MockSpiral)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No part of this mocking is needed?

Copy link
Copy Markdown
Collaborator Author

@alperkent alperkent Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want the feature extraction functions to input the spiral object rather than only the needed columns of the dataframe, because I think it would make it easier to just call all of them with the same inputs in the orchestrator. I did not want to just import the whole dataframe instead of the spiral object because I thought maybe some features that we will extract later might need to use the metadata info like task name or handedness, or we could decide to prioritize getting a feature like task duration first and instead if calculating it separately for each other feature that uses it, we could just add it to the spiral object.
Should I just input the valid spiral fixture and change the data to this sine wave data? Because instantiating a spiral object without proper columns and metadata just throws errors.

Comment thread tests/unit/test_drawing_error.py Outdated

def test_calculate_area_under_curve(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that the area under the curve is calculated correctly."""
x = np.linspace(-np.pi / 2, 6 * np.pi / 4, 100)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why such a complicated x-axis data points? If you just do 0-2pi I'm pretty sure this is a nice easy calculation for AUC of the difference (and an exact value)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I basically wanted to test that the shapely method is able to handle intersecting lines. And this area is equal to 8 but I just wanted to confirm with the integrate function.

Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments, the main question is why use shapely do begin with and not just scipy integration like you do in the test?

…at] for area under curve calculations and Hausdorff metrics, and refactor drawing error tests to use pytest fixture instead of monkeypatch
Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@alperkent alperkent merged commit 1a95356 into main Apr 23, 2025
16 checks passed
@alperkent alperkent deleted the alperkent/issue19 branch April 23, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request task A development task intended for Github Projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task: Implement drawing_error.py module, computation of features that capture drawing error

2 participants